var _self;
import { FriendModel } from "../../models/friend.js";
var _FriendModel = new FriendModel();
Page({
  data: {
    myFriendList: [],
    pagenation: {
      pageNum: 1,  //页码
      pageSize: 10, //每页显示多少数据
      pages: 0,   //一共有几页
      total: 0,
      hasMore: true //是否有更多数据 
    },
    isNoMoreData: false
  },
  onLoad: function (options) {
    _self = this;
    this.getFriends(_self.data.pagenation);
  },
  getFriends: function (param) {

    _FriendModel.getFriendList(param, function (data) {
      if (data.length > 0) {
        console.log(data[0])
        if (data[0].list.length < _self.data.pagenation.pageSize) {
          _self.setData({
            ['pagenation.hasMore']: false,
            isNoMoreData: true
          })
        }
        _self.setData({
          ['pagenation.pageNum']: data[0].pageNum,
          ['pagenation.pageSize']: data[0].pageSize,
          ['pagenation.pages']: data[0].pages,
          ['pagenation.total']: data[0].total,
          myFriendList: _self.data.myFriendList.concat(data[0].list)
        })

        console.log(_self.data.myFriendList)
      }
    })
  },
  loadMoreFriends: function () {
    let pagenation = _self.data.pagenation;
    if (pagenation.hasMore) {
      let newPageNum = pagenation.pageNum + 1;
      let pages = pagenation.pages;
      if (newPageNum > pages) {
        _self.setData({
          ['pagenation.hasMore']: false,
          isNoMoreData: true
        })
      } else {
        _self.setData({
          ['pagenation.pageNum']: newPageNum
        })
        _self.getFriends(_self.data.pagenation);
      }


    } else {
      _self.setData({
        isNoMoreData: true
      })
    }
  }
})